//14.9 - Drawing.cpp - Mark Lee - Prima Publishing #include "drawing.h" void DisplayScreen(char* bmp) //displays the specified bitmap on the screen { //prepare blitting info DDBLTFX ddbltfx; ZeroMemory(&ddbltfx,sizeof(ddbltfx)); ddbltfx.dwSize = sizeof(ddbltfx); //create a surface from the bitmap g_pddsone = DDLoadBitmap(g_pdd,bmp,800,600); //blt the surface to the back buffer g_pddsback->Blt(NULL,g_pddsone, NULL,NULL,&ddbltfx); //display this prepared screen g_pddsprimary->Flip(NULL,0); } void Redraw() //function used to draw the screen after the first time { ship->Draw(); } void LoadMaps() //create HBITMAPs from all of the map files { //use Win32 LoadImage function entireMap[0][0] = (HBITMAP)LoadImage(NULL, "map1.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[1][0] = (HBITMAP)LoadImage(NULL, "map2.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[2][0] = (HBITMAP)LoadImage(NULL, "map3.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[0][1] = (HBITMAP)LoadImage(NULL, "map4.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[1][1] = (HBITMAP)LoadImage(NULL, "map5.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[2][1] = (HBITMAP)LoadImage(NULL, "map6.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[0][2] = (HBITMAP)LoadImage(NULL, "map7.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[1][2] = (HBITMAP)LoadImage(NULL, "map8.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); entireMap[2][2] = (HBITMAP)LoadImage(NULL, "map9.bmp",IMAGE_BITMAP, 800,600, LR_LOADFROMFILE | LR_CREATEDIBSECTION); //first map is top left corner currentMapX = 0; currentMapY = 0; } void InitializeDirectX(HWND hWnd) //performs all DirectX initialization { //create the DirectDraw object hRet = DirectDrawCreateEx(NULL, (void**)&g_pdd, IID_IDirectDraw7, NULL); if(hRet != DD_OK) MessageBox(hWnd, "DirectDrawCreateEx Failed", "Error", NULL); //Set the Cooperative Level hRet = g_pdd->SetCooperativeLevel(hWnd, DDSCL_FULLSCREEN | DDSCL_EXCLUSIVE); if(hRet != DD_OK) MessageBox(hWnd, "SetCooperativeLevel Failed", "Error", NULL);; //Set the display mode: 800x600 with 16 bits per pixel hRet = g_pdd->SetDisplayMode(800, 600, 16,0,0); if(hRet != DD_OK) MessageBox(hWnd, "SetDisplayMode Failed", "Error", NULL);; //prepare primary surface info ZeroMemory(&ddsd,sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ddsd.dwFlags = DDSD_CAPS | DDSD_BACKBUFFERCOUNT; ddsd.dwBackBufferCount = 1; ddsd.ddsCaps.dwCaps = DDSCAPS_PRIMARYSURFACE | DDSCAPS_FLIP | DDSCAPS_COMPLEX; //create the surface hRet = g_pdd->CreateSurface(&ddsd, &g_pddsprimary, NULL); if (hRet != DD_OK) MessageBox(hWnd, "CreateSurface Failed", "Error", NULL); //prepare the back buffer info ZeroMemory(&ddsc,sizeof(ddsc)); ddsc.dwCaps = DDSCAPS_BACKBUFFER; //get a pointer to the back buffer hRet = g_pddsprimary->GetAttachedSurface(&ddsc, &g_pddsback); } void Draw() //initial drawing function - draws the game screen { //create the ship ship = new Ship(); //draw the ship on top of the map ship->Draw(); }